<?php
namespace App\Services;

class ToolsService
{
    /**
     * 成功返回接口
     * @param $msg
     * @param int $code
     * @param array $data
     * @return \Illuminate\Http\JsonResponse
     */
    public static function ok($data=[],$code=1,$msg='ok')
    {
        $rel = [
            'code' => $code,
            'msg' => $msg,
        ];

        if($data){
            $rel['data'] = $data;
        }

        return response()->json($rel)->send();
    }

    /**
     * 失败返回接口
     * @param $msg
     * @param int $code
     * @param array $data
     * @return \Illuminate\Http\JsonResponse
     */
    public static function fail($msg='fail',$code=0,$data=[])
    {
        $rel = [
            'code' => $code,
            'msg' => $msg
        ];

        if($data){
            $rel['data'] = $data;
        }

        return response()->json($rel)->send();
    }
}